package logic

import (
	"context"
	"furniture/models/mysql"

	"furniture/furniturerpc/furniturerpc"
	"furniture/furniturerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FurnitureShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFurnitureShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FurnitureShowLogic {
	return &FurnitureShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FurnitureShowLogic) FurnitureShow(in *furniturerpc.FurnitureShowRequest) (*furniturerpc.FurnitureShowResponse, error) {
	// todo: add your logic here and delete this line
	var furnitures mysql.FurnitureClass

	mysql.DB.Debug().Where("furnitures.id=?", in.FurnitureId).Table("furnitures").
		Select("furnitures.*, classes.name as class_name, brands.name as brand_name").
		Joins("left join classes on classes.id=furnitures.class_id").
		Joins("left join brands on brands.id=furnitures.brand_id").
		Find(&furnitures)

	return &furniturerpc.FurnitureShowResponse{
		Title:     furnitures.Title,
		ClassName: furnitures.ClassName,
		BrandName: furnitures.BrandName,
	}, nil
}
